package com.scrcu.cloud.wechat.home.endpoint.customer.service.Iml;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.scrcu.cloud.wechat.home.endpoint.common.model.RestResponse;
import com.scrcu.cloud.wechat.home.endpoint.customer.entity.Institution;
import com.scrcu.cloud.wechat.home.endpoint.customer.mapper.InstMapper;
import com.scrcu.cloud.wechat.home.endpoint.customer.service.ICityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
@Slf4j
public class CityServiceIml extends ServiceImpl<InstMapper, Institution> implements ICityService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private InstMapper inst_mapper;

    @Override
    public RestResponse getByCity(String city_id, String county_id) {
        log.info(city_id+":"+county_id);
        ArrayList<Institution> institutions  = (ArrayList<Institution>) getBaseMapper().getAllByCityCountyId(city_id,county_id);
//        System.out.println(institutions);
        return RestResponse.success(institutions);
    }

    @Override
    public RestResponse getByCityName(String cityname) {
        log.info(cityname);
//        QueryWrapper<Institution> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("city_name",cityname);
////        queryWrapper.like("city_name", "%"+cityname+"%");
//
//        List<Institution> insrList = inst_mapper.selectList(queryWrapper);

        ArrayList<Institution> institutions  = (ArrayList<Institution>) getBaseMapper().getAllByCityName(cityname);
//        System.out.println(institutions);
        return RestResponse.success(institutions);
    }

    @Override
    public RestResponse getAllData() {
        ArrayList<Institution> institutions  = (ArrayList<Institution>) getBaseMapper().getAllData();
//        System.out.println(institutions);
        return RestResponse.success(institutions);
    }

    @Override
    public RestResponse getByInstName(String instName) {
        ArrayList<Institution> institutions  = (ArrayList<Institution>) getBaseMapper().getByInstName(instName);
//        System.out.println(institutions);
        return RestResponse.success(institutions);
    }

    @Override
    public RestResponse getAllByAreaName(String cityname,String areaname) {
        log.info("截取前的area为>"+areaname);
        if (areaname.length()>=3){
            areaname = areaname.substring(0,2);
        }
        log.info("截取后的area为>"+areaname);
//        QueryWrapper<Institution> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("city_name",cityname);
////        queryWrapper.like("city_name", "%"+cityname+"%");
//
//        List<Institution> insrList = inst_mapper.selectList(queryWrapper);

        ArrayList<Institution> institutions  = (ArrayList<Institution>) getBaseMapper().getAllByAreaName(cityname,areaname);
//        System.out.println(institutions);
        return RestResponse.success(institutions);
    }

}
